package com.railway.switchs.action.log;

import com.railway.switchs.domain.query.log.LoginLogQuery;
import com.railway.switchs.enums.EnumReturnResult;
import com.railway.switchs.service.log.ILoginLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName LoginLogAction
 * @Author 魏梓晟
 * @Version 1.0
 **/
@Controller
@Slf4j
@RequestMapping("/back/loginLog")
public class LoginLogAction {

    @Autowired
    private ILoginLogService loginLogService;

    /**
     * 登录日志
     * @return
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public String loginLog(){
        return "loginLog/list";
    }

    /**
     * 获取登录日志数据
     * @param query
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getList",method = RequestMethod.POST)
    public LoginLogQuery getLoinLogList(LoginLogQuery query){
        try{
            query = loginLogService.query(query);
            query.setCode(EnumReturnResult.RETURN_200.getCode());
        } catch (Exception e) {
            log.error("获取登录日志列表数据异常", e);
            query.setCode(EnumReturnResult.RETURN_404.getCode());
            query.setCode("获取登录日志数据异常");
        }
        return query;
    }
}
